package org.erp.store.infrastructure.remote;

import lombok.extern.log4j.Log4j2;
import org.erp.common.constant.Constants;
import org.erp.common.domain.Result;
import org.erp.common.exception.ServiceException;
import org.erp.store.domain.dto.DeviceInventoryRemoteDto;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Log4j2
@Component
public class ProductRemoteClient {

    @Resource
    private ProductFeignClient productFeignClient;

    public String productCallback(DeviceInventoryRemoteDto remoteDto) {
        Result<String> resp = productFeignClient.productCallback(remoteDto);
        if (resp == null) {
            throw new ServiceException("远程设备信息回调失败，返回空响应");
        }
        log.info("远程设备信息回调响应: {}", resp);
        Integer code = resp.getCode();
        if (code != Constants.SUCCESS) {
            String msg = resp.getMsg() != null ? resp.getMsg() : "远程接口返回失败";
            throw new ServiceException("远程设备信息回调失败: " + msg );
        }
        return resp.getData();
    }
}